import connect
# 高级查询import connect
client = connect.connect()

# 使用数据库test
db = client['test']

# 获取对应的集合（列表）
collection = db.test

# 插入数据
insert_data = [
    {
        "key": "111",
        "age": 18,
        "name": "john"
    },
    {
        "key": "222",
        "age": 20,
        "name": "lucy"
    },
    {
        "key": "333",
        "age": 22,
        "name": "mike"
    },
]
collection.insert_many(insert_data)
# 我们需要查找年龄  19 <= age <= 21的数据
result = collection.find({
    "$and": [
        { "age": { "$gt": 19 } },
        { "age": { "$lt": 21 } }
    ]
})
for data in result:
    print(data)
